/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.sim.api.exec;

import bgu.ppm.sim.api.mas.MASModule;
import bgu.sonar.util.evt.EventListeners;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author User
 */
public interface TickBasedExecutionSystem extends Runnable, MASModule {

    void addAll(Collection<? extends TickBasedExecutable> exacutables);

    void removeAll(Collection<TickBasedExecutable> exacutables);

    void add(TickBasedExecutable exacutables);

    void remove(TickBasedExecutable exacutables);

    void stop();

    EventListeners<ExecutionListener> getListeners();

    public interface ExecutionListener {

        void beforeExecutableAdded(TickBasedExecutionSystem execs, TickBasedExecutable executable);
        
        void afterExecutableAdded(TickBasedExecutionSystem execs, TickBasedExecutable executable);
        
        void beforeExecutableRemoved(TickBasedExecutionSystem execs, TickBasedExecutable executable);
        
        void afterExecutableRemoved(TickBasedExecutionSystem execs, TickBasedExecutable executable);
        
        /**
         * this function should be thread safe.
         *
         * @param execs
         * @param executable
         */
        void beforeTick(TickBasedExecutionSystem execs, TickBasedExecutable executable);

        /**
         * this function should be thread safe.
         *
         * @param execs
         * @param executable
         */
        void afterTick(TickBasedExecutionSystem execs, TickBasedExecutable executable);

        /**
         * this function should be thread safe.
         *
         * @param execs
         * @param executable
         */        
        void onExecutablesEnded(TickBasedExecutionSystem execs, List<TickBasedExecutable> executables);
    }
}
